load K_session01_cropped;
%load K_sequence;
%load K_iphone_front;
%K = Kguess;

X = reconstruction_calibrated(K, xim);

% plot the reconstruction
%figure; 
hold on;
plot3(X(1,:,1),X(2,:,1),X(3,:,1),'k.'); 
xlabel('x'); ylabel('y'); zlabel('z');
draw_scale = X(3,1,1)/10;
title('Calibrated reconstruction'); 
view(220,20); box on; grid off; axis equal; 

% guess intrinsic parameter matrix
opt = sprintf('%%0%dd',spaces);
index = sprintf(opt,start_frame);
first = sprintf('%s%s.%s',seq_name,index,image_type); 
img = imread(first);
[ydim,xdim,cdim] = size(img);

fguess =  max(xdim,ydim);
Kguess = [fguess 0 xdim/2; 0 fguess ydim/2; 0 0 1];

Xe = reconstruction_uncalibrated(Kguess, xim);

% plot euclidean reconstruction
figure;  
gs = 100; % global scale
plot3(gs*Xe(1,:,1),gs*Xe(2,:,1),gs*Xe(3,:,1),'k.');  hold on; box on;
xlabel('x'); ylabel('y'); zlabel('z');
draw_scale = gs*Xe(3,1,1)/6;
title('Uncalibrated Euclidean reconstruction from multiple views'); 
view(220,20); grid off; axis equal; %  axis off; 
axis equal; box on; % view(-8,-60);

%fguess =  max(xdim,ydim);
%Aguess = [fguess 0 xdim/2; 0 fguess ydim/2; 0 0 1];